package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.Order;
import com.qf.entity.WmsUser;
import com.qf.service.ArrivalService;
import com.qf.until.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * --- 天道酬勤 ---
 *
 * @author Xiaoze
 * @date 2024/7/25
 * @desc
 */
@RestController
@RequestMapping("/wms/arrival")
public class ArrivalController {
    @Autowired
    private ArrivalService arrivalService;

    /**
     * 获取全部信息
     * @param map
     * @return
     */
    @GetMapping("/list")
    public R findAll(@RequestParam HashMap<String, String> map) {
        int pageNum = Integer.parseInt(map.get("pageNum"));
        int PageSize = Integer.parseInt(map.get("pageSize"));
        PageHelper.startPage(pageNum, PageSize);
        List<Order> list = arrivalService.findAll(map);
        PageInfo<Order> info = new PageInfo<>(list);
        return R.ok(info);
    }

    /**
     * 根据id进行单个删除
     * @param id
     * @return
     */
    @GetMapping("/delOrderById")
    public R delOrderById(int id) {
        boolean isOk = arrivalService.delOrderById(id);
        return R.ok(isOk);
    }
    /**
     * 批量删除
     */
    @GetMapping("delBatch")
    public R delBatch(@RequestParam List<Integer> ids) {
        boolean isOk = arrivalService.delBatch(ids);
        return R.ok(isOk);
    }
    /**
     * 根据单行orderId 查询这一行的所有信息
     */
    @GetMapping("/detail")
    public R detail(int id) {
        List<Order> list = arrivalService.detail(id);
        return R.ok(list);
    }
    /**
     * 查询所有确认收货人
     */
    @GetMapping("/findUserName")
    public R findUserName() {
        List<WmsUser> list = arrivalService.findUserName();
        return R.ok(list);
    }
    /**
     * 入库
     */
    @PostMapping("/entry")
    public R entry(@RequestBody Order order) {

        boolean isOk = arrivalService.entry(order);
        return R.ok(isOk);
    }
}
